<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="计划标题" prop="title">
                <el-input v-model="queryParams.title" placeholder="请输入计划标题" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="单据编码" prop="billCode">
                <el-input v-model="queryParams.billCode" placeholder="请输入单据编码" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="申请流程" prop="flowKey">
                <el-input v-model="queryParams.flowKey" placeholder="请输入申请流程" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="流程状态" prop="status">
                <el-select v-model="queryParams.status" placeholder="请选择流程状态" clearable>
                    <el-option v-for="dict in dict.type.oa_flow_billstatus" :key="dict.value" :label="dict.label" :value="dict.value"/>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <TableCard>
            <el-table :border="Global.tableShowBorder" v-loading="loading" :data="workPlanList">
                <el-table-column type="selection" width="55" align="center"/>
                <el-table-column label="单据编码" align="center" prop="billCode"/>
                <el-table-column label="计划人" align="center" prop="planUserNickname"/>
                <el-table-column label="计划标题" align="center" prop="title"/>
                <el-table-column label="提交时间" align="center" prop="submitTime" width="180">
                    <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.submitTime, '{y}-{m}-{d}') }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="流程状态" align="center" prop="status">
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.oa_flow_billstatus" :value="scope.row.status"/>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <el-button size="mini" type="text" icon="el-icon-view" @click="planTrack(scope.row)" v-hasPermi="['oa:carApply:edit']">计划跟踪</el-button>
                        <el-button size="mini" type="text" icon="el-icon-rank" @click="flowDetail(scope.row)" v-hasPermi="['oa:carApply:edit']">流程信息</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
        </TableCard>

        <FlowInfo :businessId="businessId" :billType="billType" v-if="showFlowInfo" :showStatus="showFlowInfo" @closeFlowInfoDialog="closeFlowInfoDialog"></FlowInfo>

    </div>
</template>

<script>
import {listWorkPlan, getWorkPlan, delWorkPlan, addWorkPlan, updateWorkPlan} from "@/api/oa/workPlan";
import {cancleFlow, submitFlow} from "@/api/workflow/processInstance";
import FlowInfo from "@/views/workflow/flow/flowInfo";
export default {
    name: "WorkPlan",
    components:{FlowInfo},
    dicts: ['oa_flow_billstatus'],
    data() {
        return {
            billType:"",
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 工作计划表格数据
            workPlanList: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                orderByColumn: "createTime",
                isAsc: "descending",
                planUserId: null,
                title: null,
                userId: null,
                deptId: null,
                billType: null,
                billCode: null,
                flowKey: null,
                flowInsId: null,
                submitTime: null,
                status: "2"
            },
            showFlowInfo:false,
            //单据类型
            businessId:""
        };
    },
    created() {
        const billType = this.$route.query && this.$route.query.billType;
        console.log("单据类型："+billType)
        if(billType){
            this.queryParams.billType = billType;
            this.billType = billType;
        }
        this.getList();
    },
    methods: {
        /** 查询工作计划列表 */
        getList() {
            this.loading = true;
            listWorkPlan(this.queryParams).then(response => {
                this.workPlanList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        /** 查看单据详情 */
        planTrack(row){
            this.$router.push({path: "/oa/workPlan/workPlan/form/track/" + row.id, query: {readonly:"1"}})
        },
        /** 流程信息 ***/
        flowDetail(row){
            this.businessId = row.id+"";
            this.showFlowInfo = true;
        },
        //关闭流程信息窗口
        closeFlowInfoDialog(){
            this.showFlowInfo = false;
        },




    }
};
</script>
